import Service from '@/api/config/request'

/**
 * @description: 获取当前的列表
 * @return {Promise}
 * @param offset
 * @param limit
 * @param isStar
 */
export const getList = ( offset,limit,isStar) => {
  return Service.request({
    data: {
      offset,
      limit,
      isStar,
    },
    url: '/api/form/list',
    method: 'POST',
  })
}

/**
 * @description: 创建一个新的表单
 * @return {Promise}
 * @param title 表单标题
 * @param subTitle 表单副标题
 * @param problems  表单问题
 *
 */
export const createForm = ( title,subTitle,problems) => {
  return Service.request({
    data: {
      title,
      subTitle,
      problems,
    },
    url: '/api/form/create',
    method: 'POST',
  })
}

/**
 * @description: 获取表单
 * @return {Promise}
 * @param id 表单ID
 *
 */
export const getForm = ( id ) => {
  return Service.request({
    data: {
     id
    },
    url: '/api/form/get',
    method: 'POST',
  })
}

/**
 * @description: 删除表单
 * @return {Promise}
 * @param id 表单ID
 *
 */
export const deleteForm = ( id ) => {
  return Service.request({
    data: {
     id
    },
    url: '/api/form/delete',
    method: 'POST',
  })
}

/**
 * @description: 表单标星
 * @return {Promise}
 * @param id 表单ID
 *
 */
export const starForm = ( id ) => {
  return Service.request({
    data: {
     id
    },
    url: '/api/form/star',
    method: 'POST',
  })
}

/**
 * @description: 取消表单标星
 * @return {Promise}
 * @param id 表单ID
 *
 */
export const cancelStarForm = ( id ) => {
  return Service.request({
    data: {
     id
    },
    url: '/api/form/cancelStar',
    method: 'POST',
  })
}

/**
 * @description: 填写表单
 * @return {Promise}
 * @param formId 表单ID
 * @param problemsList  问题列表
 */
export const inputForm = ( formId , problemsList ) => {
  return Service.request({
    data: {
      formId,
      problemsList,
    },
    url: '/api/form/input',
    method: 'POST',
  })
}

/**
 * @description: 获取表单填写详情
 * @return {Promise}
 * @param formId 表单ID
 */
export const getFormResult = ( formId ) => {
  return Service.request({
    url: '/api/formResult/'+formId,
    method: 'GET',
  })
}

/**
 * @description: 获取表单单个填写详情
 * @return {Promise}
 * @param id 表单ID
 */
export const getDetail = ( id ) => {
  return Service.request({
    url: '/api/detail/'+id,
    method: 'POST',
  })
}

/**
 * @description: 开始收集表单
 * @return {Promise}
 * @param id 表单ID
 */
export const startForm = ( id ) => {
  return Service.request({
    data:{
      id,
    },
    url: '/api/start',
    method: 'POST',
  })
}

/**
 * @description: 结束收集表单
 * @return {Promise}
 * @param id 表单ID
 */
export const endForm = ( id ) => {
  return Service.request({
    data:{
      id,
    },
    url: '/api/end',
    method: 'POST',
  })
}
